﻿using System;
using System.Collections.Generic;

using E.BLL;
using E.Enum;
using E.Model;
using E.Web.UI.Page;

using X.Common;

namespace E.Web.Teacher.exam
{
    public partial class InputHandle : TeacherBasePage
    {
        protected override void ShowPage()
        {
            if (ispost)
            {
                string uid_v = XRequest.GetString("uid_v");
                string scid_v = XRequest.GetString("scid_v");
                string s_v = XRequest.GetString("s_v");

                if (!uid_v.Equals("") && !scid_v.Equals("") && !s_v.Equals(""))
                {
                    string[] uidArr;
                    string[] scidArr;
                    string[] sArr;

                    if (uid_v.IndexOf(",") != -1)
                    {
                        uidArr = uid_v.Split(',');
                        scidArr = scid_v.Split(',');
                        sArr = s_v.Split(',');
                    }
                    else
                    {
                        uidArr = new string[] { uid_v };
                        scidArr = new string[] { scid_v };
                        sArr = new string[] { s_v };
                    }

                    bool err = false;
                    bool repeat = false;

                    for (int i = 0; i < uidArr.Length; i++)
                    {
                        if (!Utils.IsNumeric(sArr[i]))
                        {
                            err = true;
                            break;
                        }
                        for (int j = 0; j < uidArr.Length; j++)
                        {
                            if (i != j)
                            {
                                if (uidArr[i].Equals(uidArr[j]) && scidArr[i].Equals(scidArr[j]))
                                {
                                    repeat = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (err || repeat)
                    {
                        ExecuteJS("alert('数据输入有误'); window.location = '/exam/ScoreInput.aspx';");
                    }
                    else
                    {
                        InputModel input = new InputModel();
                        input.UserIDStr = uid_v;
                        input.UserIDArray = uidArr;
                        input.ScoreCategoryIDArray = scidArr;
                        input.ScoreArray = sArr;

                        int rst = (new ExamBLL()).UserInputScoreHandle(input);

                        if (rst > 0)
                        {
                            ExecuteJS("alert('操作成功'); window.location = '/exam/ScoreInput.aspx';");
                        }
                        else
                        {
                            ExecuteJS("alert('操作失败'); window.location = '/exam/ScoreInput.aspx';");
                        }
                    }
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
